package cn.com.nou.base.controller.login;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import cn.com.nou.base.service.login.LoginCheckService;
import cn.com.nou.common.entity.NouAccountInfo;
import cn.com.nou.common.entity.NouUserInfoT;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(path="/login")
public class LoginCheckController {
	@Autowired
	private LoginCheckService loginCheckService;
	
	@ApiOperation(value = "登录-验证登录信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "passWord", value = "密码", required = true, dataType = "String", paramType = "body")
	})
	@PostMapping(path = "/check")
	@ResponseBody
	public Map<String,Object> getAccountInfo(@RequestBody NouUserInfoT nouUserInfoT,HttpSession session) {
		Map<String,Object> model = new HashMap<>();
		NouUserInfoT user = loginCheckService.checkLogin(nouUserInfoT.getUserName(), nouUserInfoT.getPassWord());
		session.setAttribute("login", user);
		model.put("user", user);
		return model;
	}
	@PostMapping(path= "/logout")
	@ResponseBody
	public String logout(HttpSession session) {
		// 注销session
		session.invalidate();
		return "0";
	}
}
